<?php

/*
 * This file is part of the yuki package.
 * Copyright (c) 2011 olamedia <olamedia@gmail.com>
 *
 * This source code is release under the MIT License.
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * yExceptionHandler
 *
 * @package yuki
 * @subpackage exception
 * @version SVN: $Id: yExceptionHandler.php 109 2011-02-19 08:11:02Z olamedia@gmail.com $
 * @revision SVN: $Revision: 109 $
 * @date $Date: 2011-02-19 08:11:02 +0000 (Sat, 19 Feb 2011) $
 * @author olamedia
 * @license http://www.opensource.org/licenses/mit-license.php MIT
 */
class yExceptionHandler{
    protected static $_instance = null;
    /**
     * Constructor.
     */
    protected function __construct(){
        
    }
    /**
     * Get yExceptionHandler instance.
     * @return yExceptionHandler
     */
    public static function getInstance(){
        if (self::$_instance === null){
            self::$_instance = new self();
        }
        return self::$_instance;
    }
    /**
     * Registers exception & error handlers
     */
    public static function register(){
        set_exception_handler(array(self::getInstance(), 'handleException'));
        set_error_handler(array(self::getInstance(), 'handleError'));
    }
    public static function handleException(Exception $exception){
        /* $event = new yEvent('exception');
          $event->setSender($sender); */
        //$trace = debug_backtrace();
        //var_dump($trace);
        $trace = $exception->getTrace();
        $class = $trace[0]['class'];
        echo $class;
        yGlobalEventDispatcher::notify($event);
    }
    public static function handleError($errno, $errstr, $errfile, $errline){
        
    }
}

yExceptionHandler::register();


